package com.example.demo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.demo.databinding.ActivityCheatBinding;
import com.example.demo.databinding.ActivityMainBinding;

import java.util.Timer;
import java.util.TimerTask;

public class CheatActivity extends AppCompatActivity {


    private int currentQuestion;
    private boolean answerIsTrue;
    private boolean isCheated = false;
    private ActivityCheatBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cheat);
        binding = ActivityCheatBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);

        Intent intent = getIntent();
        answerIsTrue = intent.getBooleanExtra("trueQuestion",false);

        setAnswerShownResult(isCheated);
        binding.showAnswerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //显示答案
                binding.trueAnswer.setText(String.valueOf(answerIsTrue));
                setAnswerShownResult(true);
                isCheated = true;
                Timer timer = new Timer();
                TimerTask timerTask = new TimerTask() {
                    @Override
                    public void run() {
//                        startActivity(new Intent(CheatActivity.this,MainActivity.class));
                        finish();
                    }
                };
                timer.schedule(timerTask,3000);
            }
        });
    }

    /**
     * 设置结果
     * @param isAnswerShown
     */
    private void setAnswerShownResult(boolean isAnswerShown) {
        Intent data = new Intent();
        data.putExtra("answerShown",isAnswerShown);
        setResult(RESULT_OK,data);
    }

}